package pta.test0809.覆盖;

import java.lang.reflect.Constructor;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        ArrayList<PersonOverride> person1 = new ArrayList<>();
        ArrayList<PersonOverride> person2 = new ArrayList<>();
        int n1 = sc.nextInt();
        for (int i = 0; i < n1; i++) {
            person1.add(new PersonOverride());
        }
        int n2 = sc.nextInt();

        for (int i = 0; i < n2; i++) {
            PersonOverride p = new PersonOverride(sc.next(),sc.nextInt(),sc.nextBoolean());

            boolean exists = false;
            for (PersonOverride p1 : person2) {
                if (p1.equals(p)) {
                    exists = true;
                    break;
                }
            }

            if (!exists) {
                person2.add(p);
            }
        }
        // 输出persons1数组中的所有对象
        for (PersonOverride person : person1) {
            System.out.println(person);
        }

        // 输出persons2数组中的所有对象
        for (PersonOverride person : person2) {
            System.out.println(person);
        }

        // 输出persons2中实际包含的对象的数量
        System.out.println(person2.size());

        // 输出PersonOverride的所有构造方法
        List<Constructor<?>> constructors = Arrays.asList(PersonOverride.class.getConstructors());
        Collections.reverse(constructors);
        System.out.println(Arrays.toString(constructors.toArray()));
    }
}

class PersonOverride{
    private String name;
    private int age;
    private boolean gender;
    public PersonOverride(String name, int age, boolean gender) {
        this.name = name;
        this.age = age;
        this.gender = gender;
    }

    public PersonOverride() {
        this("default", 1, true);
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + age;
        result = prime * result + (gender ? 1231 : 1237);
        result = prime * result + ((name == null) ? 0 : name.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == this) {
            return true;
        }

        if (!(obj instanceof PersonOverride)) {
            return false;
        }

        PersonOverride other = (PersonOverride) obj;
        return name.equals(other.name) && age == other.age && gender == other.gender;
    }
    @Override
    public String toString() {
        return name + "-" + age + "-"+ gender;
    }
}
